/**
 * 详情对话框
 */
var BtyExpendInfoDlg = {
    data: {
        shopCode: "",
        shopName: "",
        money: "",
        remark: "",
        time: "",
        createUser: "",
        createTime: "",
        modifyUser: "",
        modifyTime: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;
    //让当前iframe弹层高度适应
    admin.iframeAuto();
    /**
     * 自定义校验规则
     */
    form.verify({
        double: function (value) {
            if (/^\d+$/.test(value) == false && /^\d+\.\d+$/.test(value) == false) {
                return '你输入的不是数字';
            }
        }
    });
    var qyAjax = new $ax("/dbiShop/shopList");
    qyAjax.set("type", 2);
    var qyResult = qyAjax.start();
    $.each(qyResult.data, function (index, data) {
        $("#shopCode").append("<option value='" + data.code + "'>" + data.name + "</option>");
    });
    form.render('select');

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/btyExpend/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    result.data.time=result.data.time.substring(0,10);
    form.val('btyExpendForm', result.data);



    laydate.render({
        elem:'#time',
        max:Feng.currentDate()
    });
    form.on('select(shopNamefilt)',function (data) {
        $("#shopName").val(data.elem[data.elem.selectedIndex].text);
    });

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/btyExpend/editItem", function (data) {
            Feng.success("更新成功！");
            window.location.href = Feng.ctxPath + '/btyExpend'
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/btyExpend'
    });

});